package cn.iocoder.yudao.module.biz.service.emergencyReservePlainDetail;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainDetail.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.emergencyReservePlainDetail.BizEmergencyReservePlainDetailDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.biz.convert.emergencyReservePlainDetail.BizEmergencyReservePlainDetailConvert;
import cn.iocoder.yudao.module.biz.dal.mysql.emergencyReservePlainDetail.BizEmergencyReservePlainDetailMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.biz.enums.ErrorCodeConstants.*;

/**
 * 预案详情 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class BizEmergencyReservePlainDetailServiceImpl implements BizEmergencyReservePlainDetailService {

    @Resource
    private BizEmergencyReservePlainDetailMapper emergencyReservePlainDetailMapper;

    @Override
    public String createEmergencyReservePlainDetail(BizEmergencyReservePlainDetailCreateReqVO createReqVO) {
        // 插入
        BizEmergencyReservePlainDetailDO emergencyReservePlainDetail = BizEmergencyReservePlainDetailConvert.INSTANCE.convert(createReqVO);
        emergencyReservePlainDetailMapper.insert(emergencyReservePlainDetail);
        // 返回
        return emergencyReservePlainDetail.getId();
    }

    @Override
    public void updateEmergencyReservePlainDetail(BizEmergencyReservePlainDetailUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateEmergencyReservePlainDetailExists(updateReqVO.getId());
        // 更新
        BizEmergencyReservePlainDetailDO updateObj = BizEmergencyReservePlainDetailConvert.INSTANCE.convert(updateReqVO);
        emergencyReservePlainDetailMapper.updateById(updateObj);
    }

    @Override
    public void deleteEmergencyReservePlainDetail(String id) {
        // 校验存在
        this.validateEmergencyReservePlainDetailExists(id);
        // 删除
        emergencyReservePlainDetailMapper.deleteById(id);
    }

    private void validateEmergencyReservePlainDetailExists(String id) {
        if (emergencyReservePlainDetailMapper.selectById(id) == null) {
            throw exception(EMERGENCY_RESERVE_PLAIN_DETAIL_NOT_EXISTS);
        }
    }

    @Override
    public BizEmergencyReservePlainDetailDO getEmergencyReservePlainDetail(String id) {
        return emergencyReservePlainDetailMapper.selectById(id);
    }

    @Override
    public List<BizEmergencyReservePlainDetailDO> getEmergencyReservePlainDetailList(Collection<String> ids) {
        return emergencyReservePlainDetailMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<BizEmergencyReservePlainDetailDO> getEmergencyReservePlainDetailPage(BizEmergencyReservePlainDetailPageReqVO pageReqVO) {
        return emergencyReservePlainDetailMapper.selectPage(pageReqVO);
    }

    @Override
    public List<BizEmergencyReservePlainDetailDO> getEmergencyReservePlainDetailList(BizEmergencyReservePlainDetailExportReqVO exportReqVO) {
        return emergencyReservePlainDetailMapper.selectList(exportReqVO);
    }

}
